import React from 'react';
import { withRouter } from 'umi';
import { Spin } from 'antd';
// import { Link }  from 'umi';
import { useRequest, defaultFormatResult, useWorkFlow } from '@/hooks';
import { WorkHandover, PersonnelHandover, ITHandover, AdministrativeHandover, FinancialSettlement } from './containers';
import { LEAVE_STATUS_OBJ } from '../dictionary';
import styles from './index.less';
import { ProfileCard } from './components';
import { getHandoverContent } from '../service';
// 离职交接
function Handover(props) {
    const { location } = props;
    const { query } = location;
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    // const { employeeCode } = query;
    const { employeeCode, type = LEAVE_STATUS_OBJ.WorkHandover, dimissionOrderId } = query;
    const params = {
        dimissionOrderId,
        employeeCode,
        type,
        matterId: query?.matterId
    };
    const { data, loading } = useRequest(() => getHandoverContent(params), {
        // const { data, loading } = useRequest(() => getHandoverDetailByOrderId(query?.dimissionOrderId), {
        ready: !!query?.dimissionOrderId,
        ...defaultFormatResult
    });
    const { view } = useWorkFlow({ launchParam: { type: 'TransferPositionApply' } });
    // 跳转到审批、审批详情页面
    const gotoApprovePage = () => {
        view({ processInstanceId: data?.dimissionOrderVO.processInstanceId });
    };
    const CurrentView = React.useMemo(() => {
        let View = null;

        switch (data?.matterDetail[0].handoverType.toString()) {
            // switch (type?.toString()) {
            // 工作交接
            case LEAVE_STATUS_OBJ.WORK_HANDOVER.toString():
                View = WorkHandover;
                break;
            // 人事交接
            case LEAVE_STATUS_OBJ.PERSONNEL_HANDOVER.toString():
                View = PersonnelHandover;
                break;
            case LEAVE_STATUS_OBJ.IT_HANDOVER.toString():
                View = ITHandover;
                break;
            case LEAVE_STATUS_OBJ.ADMINISTRATIVE_HANDOVER.toString():
                View = AdministrativeHandover;
                break;
            case LEAVE_STATUS_OBJ.FINANCIAL_SETTLEMENT.toString():
                View = FinancialSettlement;
                break;
            default:
                break;
        }
        return View;
    }, [data]);
    // }, [type]);
    return (
        <div className={styles.handover_container}>
            <div className={styles.top_card}>
                <ProfileCard employeeCode={employeeCode} />
            </div>
            <Spin spinning={loading}>
                <div className={styles.line}></div>
                <div className={styles.content}>
                    <div>
                        <span>离职申请：</span>
                        <span style={{ color: '#ffb957', cursor: 'pointer' }} onClick={gotoApprovePage}>
                            查看详情
                        </span>
                        {/* <Link>
                            查看详情
                        </Link> */}
                    </div>
                    <div>
                        <span>离职日期：</span>
                        <span>{data?.dimissionOrderVO.finalDimissionDate || '--'} </span>
                    </div>
                </div>
                {/* <div className={styles.line}></div> */}
                <div className={styles.content_view}>{data && <CurrentView {...query} data={data} />}</div>
            </Spin>
        </div>
    );
}
export default withRouter(Handover);
